package com.qijian.business.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qijian.business.domain.query.ProductionDetailSalaryQuery;
import com.qijian.business.domain.vo.ProductionDetailSalaryVo;
import com.qijian.common.utils.DateUtils;
import com.qijian.common.utils.SecurityUtils;
import com.qijian.common.utils.StringUtils;
import com.qijian.common.utils.mybatis.WhereEntityTool;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.qijian.business.mapper.ProductionDetailSalaryMapper;
import com.qijian.business.domain.ProductionDetailSalary;
import com.qijian.business.service.IProductionDetailSalaryService;

/**
 * 报工工资Service业务层处理
 *
 * @author qijian
 * @date 2025-03-29
 */
@Service
@RequiredArgsConstructor
public class ProductionDetailSalaryServiceImpl extends ServiceImpl<ProductionDetailSalaryMapper, ProductionDetailSalary> implements IProductionDetailSalaryService {

    private final ProductionDetailSalaryMapper productionDetailSalaryMapper;

    @Override
    public Page<ProductionDetailSalaryVo> getTeamProduction(ProductionDetailSalaryQuery productionDetailSalaryQuery, Page<ProductionDetailSalary> page) {
        if (StringUtils.isEmpty(productionDetailSalaryQuery.getDate())) {
            productionDetailSalaryQuery.setDate(DateUtils.getDate());
        }
        Page<ProductionDetailSalaryVo> teamProduction = productionDetailSalaryMapper.getTeamProduction(SecurityUtils.getUserId(), WhereEntityTool.invoke(productionDetailSalaryQuery), page);
        teamProduction.getRecords().forEach(productionDetailSalaryVo -> {
            if (productionDetailSalaryVo.getTeamLeaderCheck() && StringUtils.isNotNull(productionDetailSalaryVo.getCheckQty())) {

                productionDetailSalaryVo.setFinishQty(productionDetailSalaryVo.getCheckQty());
            }
        });
        return  teamProduction;
    }

    @Override
    public List<ProductionDetailSalaryVo> getTeamSalary(ProductionDetailSalaryQuery productionDetailSalaryQuery) {
        if (StringUtils.isEmpty(productionDetailSalaryQuery.getDate())) {
            productionDetailSalaryQuery.setDate(DateUtils.getDate());
        }
        return productionDetailSalaryMapper.getTeamSalary(SecurityUtils.getUserId(), WhereEntityTool.invoke(productionDetailSalaryQuery));
    }
}
